﻿#include "collision.h"


CircleCollisionBox::CircleCollisionBox()
    : CollisionBox(CollisionBoxType::Circle), x_(0), y_(0), radius_(1) {}
CircleCollisionBox::CircleCollisionBox(float x, float y, float radius)
	: CollisionBox(CollisionBoxType::Circle), 
    x_(std::abs(x)), y_(std::abs(y)), radius_(std::abs(radius)) {}

float CircleCollisionBox::getX() const { return x_; }
float CircleCollisionBox::getY() const { return y_; }
float CircleCollisionBox::getRadius() const { return radius_; }

bool CircleCollisionBox::setX(float x) {
    if (x >= 0) {
        x_ = x;
        return true;
    }
    return false;
}
bool CircleCollisionBox::setY(float y) {
    if (y >= 0) {
        y_ = y;
        return true;
    }
    return false;
}
bool CircleCollisionBox::setRadius(float radius) {
    if (radius >= 0) {
        radius_ = radius;
        return true;
    }
    return false;
}

bool CircleCollisionBox::checkCollision(const CollisionBox& other) const {
	return other.checkCollisionWithCircle(*this);
}

bool CircleCollisionBox::checkCollisionWithPoint(const PointCollisionBox& point) const {
    return point.checkCollisionWithCircle(*this);
}

bool CircleCollisionBox::checkCollisionWithRectangle(const RectangleCollisionBox& rect) const {
    return rect.checkCollisionWithCircle(*this);
}

bool CircleCollisionBox::checkCollisionWithCircle(const CircleCollisionBox& circle) const {
    float dx = x_ - circle.getX();
    float dy = y_ - circle.getY();
    float sumRadius = radius_ + circle.getRadius();
    return (dx * dx + dy * dy) <= (sumRadius * sumRadius);
}